package _36define;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class Demo2 {
    public  static List<Student1> students;
    static {
        students= Arrays.asList(
                new Student1(1,"zs","wuhan",19),
                new Student1(2,"ls","beijing",17),
                new Student1(3,"ww","nanyang",18),
                new Student1(4,"zl","hubei",19),
                new Student1(5,"lq","zhengzhou",20)
                );
    }
    public static void main(String[] args) {
        List<Student1> s=students;
        List<Student1> list=s.stream().filter(new Predicate<Student1>() {
            @Override
            public boolean test(Student1 student1) {
                return student1.getAddress().equals("hubei");
            }
        }).collect(Collectors.toList());
        System.out.println(list.size());


        List<Student1> s1=students;
        List<Student1> list1=s1.stream().filter(new Predicate<Student1>() {
            @Override
            public boolean test(Student1 student1) {
                return student1.getAge()>18;
            }
        }).collect(Collectors.toList());
        System.out.println(list1.size());
        System.out.println(list1);


        List<Student1> s2=students;
        List<Student1> list2=s.stream().filter(new Predicate<Student1>() {
            @Override
            public boolean test(Student1 student1) {
                return student1.getName().contains("z")&&student1.getAge()>18;
            }
        }).collect(Collectors.toList());
        System.out.println(list2.size());
        System.out.println(list2);
    }

}
class Student1{
    int id;
    String name;
    String address;
    int age;

    public Student1(int id, String name, String address, int age) {
        this.id = id;
        this.name = name;
        this.address = address;
        this.age = age;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public String getAddress() {
        return address;
    }

    public int getAge() {
        return age;
    }

    @Override
    public String toString() {
        return "Student1{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", address='" + address + '\'' +
                ", age=" + age +
                '}';
    }
}
